﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using EnglishRegister.Utilities;
using EnglishRegister.Entities;
namespace EnglishRegister.Business
{
    public class StudentBL
    {
        public static IList GetAllStudentByCourse(Guid CourseID)
        {
            var result = from q in StudentModel.GetTable()
                         where q.CourseID == CourseID
                         select new
                         {
                             Name = q.FirstName + ' ' + q.LastName,
                             Address = q.Address,
                             Phone = q.PhoneNo,
                             ID = q.ID
                         };


            return result.ToList();
        }

        public static StudentModel GetByPrimaryKey(int key)
        {
            return StudentModel.GetTable().Where(p => p.ID == key).First();
        }

        public static bool CheckExistedStudent(Guid CourseID)
        {
            IList checkList = GetAllStudentByCourse(CourseID);
            return checkList == null && checkList.Count > 0;
        }

        public static void Insert(StudentModel insertObj)
        {
            insertObj.Insert();
        }

        public static void Update(StudentModel updateObj)
        {
            updateObj.Update();
        }

        public static void Delete(int key)
        {
            StudentModel deleteObj = StudentModel.GetTable().Where(p => p.ID == key).FirstOrDefault();
            if (deleteObj != null)
                deleteObj.Delete();
        }
    }
}
